#include <iostream>
#include <string>
#include <memory>

class Fruit
{
public:
    Fruit() {}
    virtual void show() = 0;
};

class Apple:public Fruit
{
    public:
    Apple(){}
   virtual void show()
    {
        std::cout<<"这是一个苹果"<<std::endl;
    }
};

class Bannana:public Fruit
{
    public:
    Bannana(){}
    virtual void show()
    {
        std::cout<<"这是一个香蕉"<<std::endl;
    }
};

class Factory
{
    public:
    static std::shared_ptr<Fruit> create(const std::string& name)
    {
        if(name=="苹果")
        {
            return std::make_shared<Apple>();
        }
        else if(name=="香蕉")
        {
            return std::make_shared<Bannana>();
        }
        return std::shared_ptr<Fruit>();
    }
};

int main()
{
    std::shared_ptr<Fruit> fruit=Factory::create("苹果");
    fruit->show();

    fruit=Factory::create("香蕉");
    fruit->show();
    
    return 0;
}